<template>
  <div class="app-container">
    <el-form :model="form" ref="form" :inline="true">
      <el-form-item label="出库状态" prop="orderStatus">
        <el-select v-model="form.orderStatus">
          <el-option
            v-for="item in dict.type.wms_shipment_status"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="出库类型" prop="optType">
        <el-select v-model="form.optType">
          <el-option
            v-for="item in dict.type.wms_shipment_type"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="出库单号" prop="inventoryOrderNo">
        <el-input v-model="form.inventoryOrderNo" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-button type="primary" plain icon="el-icon-plus" @click="updateRow(0,{})">出库</el-button>
    <el-table
      v-loading="loading"
      :data="list"
    >
      <el-table-column type="index" label="序号" align="center">
        <template slot-scope="scope">
          <span>{{ (form.pageNum - 1) * form.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="inventoryOrderNo" label="出库单号" align="center">
        <template slot-scope="scope">
          <el-link type="primary" @click="updateRow(1,scope.row)">{{ scope.row.inventoryOrderNo }}</el-link>
        </template>
      </el-table-column>
      <el-table-column prop="reOrderNo" label="关联单号" align="center"/>
      <el-table-column prop="warehouseName" label="仓库名称" align="center"/>
      <el-table-column prop="warehouseSpaceName" label="仓位名称" align="center"/>
      <el-table-column prop="totalQuantity" label="总数量" align="center"/>
      <el-table-column prop="orderStatus" label="出库状态" align="center">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_shipment_status" :value="scope.row.orderStatus"/>
        </template>
      </el-table-column>
      <el-table-column prop="optType" label="出库类型" align="center">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_shipment_type" :value="scope.row.optType"/>
        </template>
      </el-table-column>
      <el-table-column prop="createName" label="操作人" align="center" width="100"/>
      <el-table-column prop="createTime" label="操作时间" align="center"/>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="updateRow(1,scope.row)"
          >详情
          </el-button>
<!--          <el-button-->
<!--            type="text"-->
<!--            v-if="scope.row.orderStatus==0"-->
<!--            @click="updateRow(2,scope.row)"-->
<!--          >出单-->
<!--          </el-button>-->
          <el-button
            type="text"
            v-if="scope.row.orderStatus==1"
            @click="updateRow(3,scope.row)"
          >出库
          </el-button>
<!--          <el-button-->
<!--            type="text"-->
<!--            @click="updateRow(2,scope.row)"-->
<!--          >修改-->
<!--          </el-button>-->
<!--          <el-button-->
<!--            type="text"-->
<!--            @click="updateRow(3,scope.row)"-->
<!--          >删除-->
<!--          </el-button>-->
        </template>
      </el-table-column>
    </el-table>
    <pagination :total="total" :page.sync="form.pageNum" :limit.sync="form.pageSize" @pagination="getList"/>

    <updateDialog ref="updateDialog" @ok="handleQuery"></updateDialog>
  </div>
</template>

<script>
import updateDialog from "./updateDialog.vue";
import {deleteOutStore, listOutStore,changeOutStore,changeOutStore2} from "@/api/goodMng";

export default {
  name: 'OutStore',
  components: {updateDialog},
  dicts:['wms_shipment_status','wms_shipment_type'],
  data() {
    return {
      loading: false,
      listShow: true,
      tabIndex: 0,
      selectList: [],
      list: [],
      form: {
        orderStatus: '',
        optType: '',
        inventoryOrderNo: '',
        pageNum: 1,
        pageSize: 10
      },
      total: 0,
      goodTypeList: [],
    }
  },
  created() {
    this.load()
  },
  methods: {
    load() {
      this.handleQuery()
    },
    handleQuery() {
      this.form.pageNum = 1
      this.getList()
    },
    resetQuery() {
      this.handleQuery()
    },
    getList() {
      this.loading = true
      listOutStore(this.form).then(res => {
        this.list = res.rows
        this.total = res.total
      }).finally(e => {
        this.loading = false
      })
    },
    updateRow(flag, row) {
      let form = JSON.parse(JSON.stringify(row))
      if (flag ==0||flag==1) {
        this.$refs.updateDialog.show(flag, form)
      }
      if(flag==2){
        this.$modal.confirm('是否确定出单').then(e=>{
          changeOutStore2({id:form.id}).then(res=>{
            this.handleQuery()
            this.$message.success('出单成功')
          })
        })

      }
      if(flag==3){
        this.$modal.confirm('是否确定出库').then(e=>{
          changeOutStore({id:form.id}).then(res=>{
            this.handleQuery()
            this.$message.success('出库成功')
          })
        })
      }
      else {
        // this.$modal.confirm('是否确定删除').then(() => {
        //   deleteOutStore(row.id).then(res => {
        //     this.handleQuery()
        //     this.$message.success('删除成功')
        //   })
        // })
      }
    }
  }
}
</script>
